/*
 * Designed and developed by 2017 skydoves (Jaewoong Eum)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.skydoves.colorpickerview;

import android.graphics.Color;
import androidx.annotation.ColorInt;
import java.util.Locale;

/** 
 * ColorUtils是一个用于颜色格式转换的工具类。
 * 提供了将整型颜色值转换为其他常用表示形式的方法，如十六进制字符串和ARGB分量数组。
 */
class ColorUtils {
  /**
   * 将整型颜色值转换为十六进制颜色代码字符串
   * 
   * @param color ARGB格式的整型颜色值
   * @return 格式为"AARRGGBB"的十六进制颜色字符串，使用大写字母表示
   */
  public static String getHexCode(@ColorInt int color) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);
    return String.format(Locale.getDefault(), "%02X%02X%02X%02X", a, r, g, b);
  }

  /**
   * 将整型颜色值分解为ARGB分量数组
   * 
   * @param color ARGB格式的整型颜色值
   * @return 包含四个元素的整型数组，依次为Alpha、Red、Green、Blue分量
   *         每个分量的值范围为0-255
   */
  public static int[] getColorARGB(@ColorInt int color) {
    int[] argb = new int[4];
    argb[0] = Color.alpha(color);
    argb[1] = Color.red(color);
    argb[2] = Color.green(color);
    argb[3] = Color.blue(color);
    return argb;
  }
}
